package br.com.news.business;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import br.com.news.business.utils.GenericBusiness;
import br.com.news.utils.business.exception.BusinessException;
import br.com.news.utils.business.interfaces.IContatoBusiness;
import br.com.news.utils.database.beans.ContatoBean;
import br.com.news.utils.database.exception.DataBaseServiceException;
import br.com.news.utils.database.interfaces.IContatoServiceDb;

@Named
public class ContatoBusiness extends GenericBusiness implements IContatoBusiness{

	@Inject
	private IContatoServiceDb contatoServiceDb;
	
	@Override
	public List<ContatoBean> findAll() throws BusinessException {
		try {
			return contatoServiceDb.findAll();
		} catch (DataBaseServiceException e) {
			throw new BusinessException(e);
		}
	}
	
	@Override
	public void save(ContatoBean contato) throws BusinessException {
		try {
			contatoServiceDb.save(contato);
		} catch (DataBaseServiceException e) {
			throw new BusinessException("erro ao tentar salvar na camada do business.",e);
		}
	}
	
	@Override
	public void update(ContatoBean contato) throws BusinessException {
		try {
			contatoServiceDb.update(contato);
		} catch (DataBaseServiceException e) {
			throw new BusinessException("Erro ao tentar dar update o contato na camada de business",e);
		}
	}
	
	@Override
	public List<ContatoBean> buscaContatosNaoEnviados() {
		return contatoServiceDb.buscaContatosNaoEnviados();
	}

}
